<template>
  <div class="transaction-service-list bg-c-fff right-height mb70">
    <div class="bread">
      <a href="javascript:void(0);" class="font-s-16">交易监控订单管理-监控员</a>
      <div class="flo-right btn-box tab">
        <span>接单开关：</span>
        <ul class="fix">
          <li class="flo-left cup" v-bind:class="{active:switchType === 1}" @click="tab(1)">打开</li>
          <li class="flo-left cup" v-bind:class="{active:switchType === 0 }" @click="tab(0)">关闭</li>
        </ul>
      </div>
    </div>
    <div class="content">
      <choose-type typename="订单状态" valuename="orderType" :itemlist="orderlist" :active="orderActive" @typechanged="onOptionChanged"></choose-type>
      <choose-type typename="监控类型" valuename="typeType" :itemlist="typelist" :active="typeActive" @typechanged="onOptionChanged"></choose-type>
      <table width="100%" class="auto">
        <tr>
          <th>订单时间</th>
          <th>订单编号</th>
          <th>发起人</th>
          <th>监控类型</th>
          <th>监控师</th>
          <th>订单状态</th>
          <th>操作</th>
        </tr>
        <tr v-for="item in list">
          <td>{{item.createTime}}</td>
          <td>{{item.id}}</td>
          <td>{{item.businessName}}</td>
          <td>{{item.monitorType | monitorTypeFilter}}</td>
          <td>{{item.monitorName}}</td>
          <td>{{item.stage | stageFilter}}</td>
          <td>
            <button class="blue-button small-btn-css" @click="onDetailsClick(item)">查看详情</button>
          </td>
        </tr>
      </table>
      <div class="fix foot-box">
        <div class="no-data-tip" v-show="list.length===0">暂无相关数据</div>
        <pagination :index="pageIndex" :total="pageTotal" v-show="this.list!=0" @pagechange="onPageChange"></pagination>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import Pagination from '../components/Pagination'
import ChooseType from '../components/ChooseType'
export default {
  components: {
    Pagination,
    ChooseType
  },
  data() {
    return {
      pageIndex: 1,
      pageTotal: 0,
      orderActive: '',
      orderlist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '进行中'
      }, {
        value: '3',
        text: '已终止'
      }, {
        value: '2',
        text: '已完成'
      }],
      typeActive: '',
      typelist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '单方监控'
      }, {
        value: '2',
        text: '双方监控'
      }, {
        value: '3',
        text: '多方监控'
      }],
      list: []
    }
  },
  mounted() {
    this.onPageChange(1)
  },
  methods: {
    onOptionChanged(type, value) {
      if (type === 'orderType') {
        this.orderActive = value
      }
      if (type === 'typeType') {
        this.typeActive = value
      }
      this.getData(1)
    },
    onPageChange(n) {
      this.getData(n)
    },
    getData(n) {
      this.$http.post('/transactionMonitorSer/user/read/list', {
        stage: this.orderActive,
        monitorType: this.typeActive,
        page: n,
        rows: 10
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.pageIndex = n
          this.pageTotal = Math.ceil(data.data.total / 10)
          this.list = data.data.rows
          // console.log(this.list)
        } else {
          console.log(data.data.msg)
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onDetailsClick(item) {
      if (item.modify === 1) {
        this.$toasted.show('正在纠错中，请稍后查看')
      } else {
        this.$router.push('/tms-order-details?id=' + item.id)
      }
    },
    tab(v) {
      this.$http.post('/transactionMonitorSer/auto', {
        status: v
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$store.dispatch('getUserInfo').then(data => {
            if (data.data.httpCode === 200) {} else {
              this.$toasted.show(data.data.msg)
            }
          }, err => {
            console.log(err)
          })
          if (v === 0) {
            this.$toasted.show('接单已关闭！')
          }
          if (v === 1) {
            this.$toasted.show('接单已打开！')
          }
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络错误')
      })
    }
  },
  computed: {
    switchType() {
      if (this.$store.state.userInfo.accept === 1) {
        return 1
      } else if (this.$store.state.userInfo.accept === 0) {
        return 0
      }
    },
    isLogin() {
      return this.$store.state.isLogin
    }
  },
  filters: {
    monitorTypeFilter(m) {
      if (m === 1) {
        return '单方监控'
      } else if (m === 2) {
        return '双方监控'
      } else if (m === 3) {
        return '多方监控'
      }
    },
    stageFilter(m) {
      if (m === 1) {
        return '进行中'
      } else if (m === 2) {
        return '已完成'
      } else if (m === 3) {
        return '已终止'
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.bread {
  padding-left: 20px;
  border-bottom: 1px solid #ddd;
}

.bread .btn-box {
  margin-top: 15px;
  margin-right: 20px;
}

.content {
  margin-top: 15px;
  padding: 0 30px 30px;
}

table {
  margin-top: 30px;
}

.foot-box {
  padding: 35px 0px 0px 0px;
}

.tab span {
  line-height: 30px;
}

.tab ul {
  height: 40px;
  line-height: 30px;
  float: right;
}

.tab ul li {
  border: 1px solid #01378c;
  padding: 0px 30px;
  margin-right: 10px;
  font-size: 15px;
  color: #01378c;
}

.tab ul li.active {
  background-color: #01378c;
  color: #fff;
}

</style>
